export default function debounce(fn: { apply: (arg0: any, arg1: any[]) => void }, delay: number | undefined) {
  // console.log('防抖中')
  let timer: string | number | NodeJS.Timeout | null | undefined = null
  const _debounce = (...arg: any[]) => {
    // console.log('Asa', arg)
    // 取消上一次的定时器
    if (timer) clearTimeout(timer)
    // 延迟执行
    timer = setTimeout(() => {
      // 外部传入的真正要执行的函数
      // @ts-ignore
      fn.apply(this, arg)
    }, delay)
  }

  return _debounce
}
